{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import json\n",
    "\n",
    "\n",
    "ocr_types_dict = {\n",
    "    'end2end': 'end2end'\n",
    "}\n",
    "\n",
    "result_folder = '../result'\n",
    "\n",
    "match_name = 'quick_match'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>text_block_Edit_dist</th>\n",
       "      <th>display_formula_CDM</th>\n",
       "      <th>table_TEDS</th>\n",
       "      <th>table_TEDS_structure_only</th>\n",
       "      <th>reading_order_Edit_dist</th>\n",
       "      <th>overall</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>end2end</th>\n",
       "      <td>0.351</td>\n",
       "      <td>0</td>\n",
       "      <td>80.012</td>\n",
       "      <td>91.455</td>\n",
       "      <td>0.161</td>\n",
       "      <td>48.304</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         text_block_Edit_dist  display_formula_CDM  table_TEDS  \\\n",
       "end2end                 0.351                    0      80.012   \n",
       "\n",
       "         table_TEDS_structure_only  reading_order_Edit_dist  overall  \n",
       "end2end                     91.455                    0.161   48.304  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# overall result: not distinguishing between Chinese and English, page-level average\n",
    "\n",
    "dict_list = []\n",
    "\n",
    "for ocr_type in ocr_types_dict.values():\n",
    "    result_path = os.path.join(result_folder, f'{ocr_type}_{match_name}_metric_result.json')\n",
    "\n",
    "    with open(result_path, 'r') as f:\n",
    "        result = json.load(f)\n",
    "    \n",
    "    save_dict = {}\n",
    "\n",
    "    for category_type, metric in [(\"text_block\", \"Edit_dist\"), (\"display_formula\", \"CDM\"), (\"table\", \"TEDS\"), (\"table\", \"TEDS_structure_only\"), (\"reading_order\", \"Edit_dist\")]:\n",
    "        if metric == 'CDM' or metric == \"TEDS\" or metric == \"TEDS_structure_only\":\n",
    "            if result[category_type][\"page\"].get(metric):\n",
    "                save_dict[category_type+'_'+metric] = result[category_type][\"page\"][metric][\"ALL\"] * 100   # page级别的avg\n",
    "            else:\n",
    "                save_dict[category_type+'_'+metric] = 0\n",
    "        else:\n",
    "            save_dict[category_type+'_'+metric] = result[category_type][\"all\"][metric].get(\"ALL_page_avg\", np.nan)\n",
    "\n",
    "    dict_list.append(save_dict)\n",
    "    \n",
    "df = pd.DataFrame(dict_list, index=ocr_types_dict.keys()).round(3)\n",
    "df['overall'] = ((1-df['text_block_Edit_dist'])*100 + df['display_formula_CDM'] + df['table_TEDS'])/3\n",
    "# df.to_csv('./overall.csv')\n",
    "\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_145052/3126657008.py:18: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  selected_columns['mean'] = reordered_df2[\"ALL\"]\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>data_source: book</th>\n",
       "      <th>data_source: PPT2PDF</th>\n",
       "      <th>data_source: research_report</th>\n",
       "      <th>data_source: colorful_textbook</th>\n",
       "      <th>data_source: exam_paper</th>\n",
       "      <th>data_source: magazine</th>\n",
       "      <th>data_source: academic_literature</th>\n",
       "      <th>data_source: note</th>\n",
       "      <th>data_source: newspaper</th>\n",
       "      <th>mean</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>end2end</th>\n",
       "      <td>0.406</td>\n",
       "      <td>0.004</td>\n",
       "      <td>0.602</td>\n",
       "      <td>0.471</td>\n",
       "      <td>0.032</td>\n",
       "      <td>0.323</td>\n",
       "      <td>0.18</td>\n",
       "      <td>0.582</td>\n",
       "      <td>0.562</td>\n",
       "      <td>0.351</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         data_source: book  data_source: PPT2PDF  \\\n",
       "end2end              0.406                 0.004   \n",
       "\n",
       "         data_source: research_report  data_source: colorful_textbook  \\\n",
       "end2end                         0.602                           0.471   \n",
       "\n",
       "         data_source: exam_paper  data_source: magazine  \\\n",
       "end2end                    0.032                  0.323   \n",
       "\n",
       "         data_source: academic_literature  data_source: note  \\\n",
       "end2end                              0.18              0.582   \n",
       "\n",
       "         data_source: newspaper   mean  \n",
       "end2end                   0.562  0.351  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# PDF type\n",
    "dict_list = []\n",
    "\n",
    "for ocr_type in ocr_types_dict.values():\n",
    "    result_path = os.path.join(result_folder, f'{ocr_type}_{match_name}_metric_result.json')\n",
    "    \n",
    "    with open(result_path, 'r') as f:\n",
    "        result = json.load(f)\n",
    "    \n",
    "    # for category_type in result.keys():\n",
    "    dict_list.append(result['text_block'][\"page\"][\"Edit_dist\"])\n",
    "df2 = pd.DataFrame(dict_list, index=ocr_types_dict.keys())\n",
    "\n",
    "reordered_df2 = df2.round(3)\n",
    "\n",
    "selected_columns = reordered_df2[[\"data_source: book\", \"data_source: PPT2PDF\", \"data_source: research_report\", \"data_source: colorful_textbook\", \"data_source: exam_paper\", \"data_source: magazine\", \"data_source: academic_literature\", \"data_source: note\", \"data_source: newspaper\"]]\n",
    "# calculate mean\n",
    "selected_columns['mean'] = reordered_df2[\"ALL\"]\n",
    "# selected_columns['variance'] = selected_columns.var(axis=1)\n",
    "# selected_columns.to_csv('./data_source.csv')\n",
    "\n",
    "selected_columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>fuzzy_scan</th>\n",
       "      <th>colorful_backgroud</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>end2end</th>\n",
       "      <td>0.471</td>\n",
       "      <td>0.062</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         fuzzy_scan  colorful_backgroud\n",
       "end2end       0.471               0.062"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# page special issue\n",
    "dict_list = []\n",
    "\n",
    "for ocr_type in ocr_types_dict.values():\n",
    "    result_path = os.path.join(result_folder, f'{ocr_type}_{match_name}_metric_result.json')\n",
    "    \n",
    "    with open(result_path, 'r') as f:\n",
    "        result = json.load(f)\n",
    "    \n",
    "    # for category_type in result.keys():\n",
    "    dict_list.append(result['text_block'][\"page\"][\"Edit_dist\"])\n",
    "df2 = pd.DataFrame(dict_list, index=ocr_types_dict.keys())\n",
    "\n",
    "reordered_df2 = df2.round(3)\n",
    "reordered_df2\n",
    "\n",
    "# selected_columns = reordered_df2[['fuzzy_scan', 'watermark', 'colorful_backgroud']] # use this for full dataset\n",
    "selected_columns = reordered_df2[[col for col in ['fuzzy_scan', 'watermark', 'colorful_backgroud'] if col in reordered_df2.columns]]\n",
    "\n",
    "# selected_columns.to_csv('./page_issue.csv')\n",
    "selected_columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>layout: single_column</th>\n",
       "      <th>layout: double_column</th>\n",
       "      <th>layout: three_column</th>\n",
       "      <th>layout: other_layout</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>end2end</th>\n",
       "      <td>0.068</td>\n",
       "      <td>0.167</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.493</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         layout: single_column  layout: double_column  layout: three_column  \\\n",
       "end2end                  0.068                  0.167                   0.0   \n",
       "\n",
       "         layout: other_layout  \n",
       "end2end                 0.493  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# reading order under different layout\n",
    "dict_list = []\n",
    "\n",
    "for ocr_type in ocr_types_dict.values():\n",
    "    result_path = os.path.join(result_folder, f'{ocr_type}_{match_name}_metric_result.json')\n",
    "    \n",
    "    with open(result_path, 'r') as f:\n",
    "        result = json.load(f)\n",
    "    \n",
    "    # for category_type in result.keys():\n",
    "    dict_list.append(result['reading_order'][\"page\"][\"Edit_dist\"])\n",
    "\n",
    "df3 = pd.DataFrame(dict_list, index=ocr_types_dict.keys())\n",
    "\n",
    "reordered_df3 = df3.round(3)\n",
    "\n",
    "\n",
    "selected_columns3 = reordered_df3[[\"layout: single_column\", \"layout: double_column\", \"layout: three_column\", \"layout: other_layout\"]]\n",
    "\n",
    "# selected_columns3.to_csv('./layout.csv')\n",
    "selected_columns3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>text_language: text_english</th>\n",
       "      <th>text_language: text_simplified_chinese</th>\n",
       "      <th>text_language: text_en_ch_mixed</th>\n",
       "      <th>text_background: white</th>\n",
       "      <th>text_background: single_colored</th>\n",
       "      <th>text_background: multi_colored</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>end2end</th>\n",
       "      <td>0.065</td>\n",
       "      <td>0.728</td>\n",
       "      <td>0.318</td>\n",
       "      <td>0.517</td>\n",
       "      <td>0.318</td>\n",
       "      <td>0.36</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         text_language: text_english  text_language: text_simplified_chinese  \\\n",
       "end2end                        0.065                                   0.728   \n",
       "\n",
       "         text_language: text_en_ch_mixed  text_background: white  \\\n",
       "end2end                            0.318                   0.517   \n",
       "\n",
       "         text_background: single_colored  text_background: multi_colored  \n",
       "end2end                            0.318                            0.36  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# text attribute\n",
    "dict_list = []\n",
    "\n",
    "for ocr_type in ocr_types_dict.values():\n",
    "    result_path = os.path.join(result_folder, f'{ocr_type}_{match_name}_metric_result.json')\n",
    "    \n",
    "    with open(result_path, 'r') as f:\n",
    "        result = json.load(f)\n",
    "    \n",
    "    # for category_type in result.keys():\n",
    "    dict_list.append(result['text_block'][\"group\"][\"Edit_dist\"])\n",
    "\n",
    "df4 = pd.DataFrame(dict_list, index=ocr_types_dict.keys())\n",
    "df4 = df4.round(3)\n",
    "\n",
    "selected_columns = df4[[\"text_language: text_english\", \"text_language: text_simplified_chinese\", \"text_language: text_en_ch_mixed\", \"text_background: white\", \"text_background: single_colored\", \"text_background: multi_colored\"]]\n",
    "\n",
    "# selected_columns.to_csv('.text_attribute.csv')\n",
    "selected_columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>language: table_en</th>\n",
       "      <th>language: table_simplified_chinese</th>\n",
       "      <th>line: full_line</th>\n",
       "      <th>line: less_line</th>\n",
       "      <th>line: fewer_line</th>\n",
       "      <th>with_span: True</th>\n",
       "      <th>with_span: False</th>\n",
       "      <th>include_equation: True</th>\n",
       "      <th>include_equation: False</th>\n",
       "      <th>include_background: True</th>\n",
       "      <th>include_background: False</th>\n",
       "      <th>table_layout: horizontal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>end2end</th>\n",
       "      <td>85.8</td>\n",
       "      <td>75.2</td>\n",
       "      <td>82.0</td>\n",
       "      <td>74.8</td>\n",
       "      <td>76.2</td>\n",
       "      <td>83.3</td>\n",
       "      <td>73.4</td>\n",
       "      <td>83.4</td>\n",
       "      <td>77.1</td>\n",
       "      <td>79.4</td>\n",
       "      <td>77.4</td>\n",
       "      <td>78.4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         language: table_en  language: table_simplified_chinese  \\\n",
       "end2end                85.8                                75.2   \n",
       "\n",
       "         line: full_line  line: less_line  line: fewer_line  with_span: True  \\\n",
       "end2end             82.0             74.8              76.2             83.3   \n",
       "\n",
       "         with_span: False  include_equation: True  include_equation: False  \\\n",
       "end2end              73.4                    83.4                     77.1   \n",
       "\n",
       "         include_background: True  include_background: False  \\\n",
       "end2end                      79.4                       77.4   \n",
       "\n",
       "         table_layout: horizontal  \n",
       "end2end                      78.4  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# table attribute\n",
    "dict_list = []\n",
    "\n",
    "for ocr_type in ocr_types_dict.values():\n",
    "    result_path = os.path.join(result_folder, f'{ocr_type}_{match_name}_metric_result.json')\n",
    "    \n",
    "    with open(result_path, 'r') as f:\n",
    "        result = json.load(f)\n",
    "    \n",
    "    # for category_type in result.keys():\n",
    "    dict_list.append(result['table'][\"group\"][\"TEDS\"])\n",
    "\n",
    "df4 = pd.DataFrame(dict_list, index=ocr_types_dict.keys())\n",
    "df4 = df4 * 100\n",
    "df4 = df4.round(1)\n",
    "\n",
    "selected_columns = df4[[col for col in [\n",
    "    \"language: table_en\", \n",
    "    \"language: table_simplified_chinese\", \n",
    "    \"language: table_en_ch_mixed\", \n",
    "    \"line: full_line\", \n",
    "    \"line: less_line\", \n",
    "    \"line: fewer_line\", \n",
    "    \"line: wireless_line\", \n",
    "    \"with_span: True\", \n",
    "    \"with_span: False\", \n",
    "    \"include_equation: True\", \n",
    "    \"include_equation: False\", \n",
    "    \"include_background: True\", \n",
    "    \"include_background: False\", \n",
    "    \"table_layout: vertical\", \n",
    "    \"table_layout: horizontal\"\n",
    "] if col in df4.columns]]\n",
    "\n",
    "# selected_columns.to_csv('./table_attribute.csv')\n",
    "selected_columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>text_language: text_english</th>\n",
       "      <th>text_language: text_simplified_chinese</th>\n",
       "      <th>text_language: text_en_ch_mixed</th>\n",
       "      <th>text_background: white</th>\n",
       "      <th>text_background: single_colored</th>\n",
       "      <th>text_background: multi_colored</th>\n",
       "      <th>text_rotate: normal</th>\n",
       "      <th>text_rotate: rotate90</th>\n",
       "      <th>text_rotate: rotate270</th>\n",
       "      <th>text_rotate: horizontal</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>OmniDocBench_easyocr_text_ocr</th>\n",
       "      <td>0.26</td>\n",
       "      <td>0.398</td>\n",
       "      <td>0.445</td>\n",
       "      <td>0.366</td>\n",
       "      <td>0.287</td>\n",
       "      <td>0.388</td>\n",
       "      <td>0.360</td>\n",
       "      <td>0.970</td>\n",
       "      <td>0.997</td>\n",
       "      <td>0.926</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>OmniDocBench_openocr_text_ocr</th>\n",
       "      <td>0.07</td>\n",
       "      <td>0.068</td>\n",
       "      <td>0.106</td>\n",
       "      <td>0.069</td>\n",
       "      <td>0.058</td>\n",
       "      <td>0.081</td>\n",
       "      <td>0.069</td>\n",
       "      <td>0.038</td>\n",
       "      <td>0.891</td>\n",
       "      <td>0.025</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               text_language: text_english  \\\n",
       "OmniDocBench_easyocr_text_ocr                         0.26   \n",
       "OmniDocBench_openocr_text_ocr                         0.07   \n",
       "\n",
       "                               text_language: text_simplified_chinese  \\\n",
       "OmniDocBench_easyocr_text_ocr                                   0.398   \n",
       "OmniDocBench_openocr_text_ocr                                   0.068   \n",
       "\n",
       "                               text_language: text_en_ch_mixed  \\\n",
       "OmniDocBench_easyocr_text_ocr                            0.445   \n",
       "OmniDocBench_openocr_text_ocr                            0.106   \n",
       "\n",
       "                               text_background: white  \\\n",
       "OmniDocBench_easyocr_text_ocr                   0.366   \n",
       "OmniDocBench_openocr_text_ocr                   0.069   \n",
       "\n",
       "                               text_background: single_colored  \\\n",
       "OmniDocBench_easyocr_text_ocr                            0.287   \n",
       "OmniDocBench_openocr_text_ocr                            0.058   \n",
       "\n",
       "                               text_background: multi_colored  \\\n",
       "OmniDocBench_easyocr_text_ocr                           0.388   \n",
       "OmniDocBench_openocr_text_ocr                           0.081   \n",
       "\n",
       "                               text_rotate: normal  text_rotate: rotate90  \\\n",
       "OmniDocBench_easyocr_text_ocr                0.360                  0.970   \n",
       "OmniDocBench_openocr_text_ocr                0.069                  0.038   \n",
       "\n",
       "                               text_rotate: rotate270  text_rotate: horizontal  \n",
       "OmniDocBench_easyocr_text_ocr                   0.997                    0.926  \n",
       "OmniDocBench_openocr_text_ocr                   0.891                    0.025  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# text Recognition\n",
    "\n",
    "ocr_types = ['OmniDocBench_easyocr_text_ocr', 'OmniDocBench_openocr_text_ocr']\n",
    "offical_names = ocr_types\n",
    "\n",
    "result_folder = '../result'\n",
    "\n",
    "dict_list = []\n",
    "\n",
    "for ocr_type in ocr_types:\n",
    "    result_path = os.path.join(result_folder, f'{ocr_type}_metric_result.json')\n",
    "    \n",
    "    with open(result_path, 'r') as f:\n",
    "        result = json.load(f)\n",
    "    \n",
    "    # for category_type in result.keys():\n",
    "    dict_list.append(result[\"group\"][\"Edit_dist\"])\n",
    "\n",
    "df4 = pd.DataFrame(dict_list, index=offical_names)\n",
    "df4 = df4.round(3)\n",
    "\n",
    "selected_columns = df4[[col for col in [\n",
    "    \"text_language: text_english\", \n",
    "    \"text_language: text_simplified_chinese\", \n",
    "    \"text_language: text_en_ch_mixed\", \n",
    "    \"text_background: white\", \n",
    "    \"text_background: single_colored\", \n",
    "    \"text_background: multi_colored\", \n",
    "    \"text_rotate: normal\", \n",
    "    \"text_rotate: rotate90\", \n",
    "    \"text_rotate: rotate270\", \n",
    "    \"text_rotate: horizontal\"\n",
    "] if col in df4.columns]]\n",
    "\n",
    "\n",
    "# selected_columns.to_csv('.text_attribute.csv')\n",
    "selected_columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# table Recognition\n",
    "\n",
    "ocr_types = ['OmniDocBench_rapidtable_ocr']\n",
    "offical_names = ocr_types\n",
    "\n",
    "result_folder = '../result'\n",
    "\n",
    "dict_list = []\n",
    "\n",
    "for ocr_type in ocr_types:\n",
    "    result_path = os.path.join(result_folder, f'{ocr_type}_metric_result.json')\n",
    "    \n",
    "    with open(result_path, 'r') as f:\n",
    "        result = json.load(f)\n",
    "    \n",
    "    # for category_type in result.keys():\n",
    "    dict_list.append(result['table'][\"group\"][\"TEDS\"])\n",
    "\n",
    "df4 = pd.DataFrame(dict_list, index=offical_names)\n",
    "df4 = df4 * 100\n",
    "df4 = df4.round(1)\n",
    "\n",
    "selected_columns = df4[[col for col in [\n",
    "    \"language: table_en\", \n",
    "    \"language: table_simplified_chinese\", \n",
    "    \"language: table_en_ch_mixed\", \n",
    "    \"line: full_line\", \n",
    "    \"line: less_line\", \n",
    "    \"line: fewer_line\", \n",
    "    \"line: wireless_line\", \n",
    "    \"with_span: True\", \n",
    "    \"with_span: False\", \n",
    "    \"include_equation: True\", \n",
    "    \"include_equation: False\", \n",
    "    \"include_background: True\", \n",
    "    \"include_background: False\", \n",
    "    \"table_layout: vertical\", \n",
    "    \"table_layout: horizontal\"\n",
    "] if col in df4.columns]]\n",
    "\n",
    "# selected_columns.to_csv('./table_attribute.csv')\n",
    "selected_columns"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "omni",
   "language": "python",
   "name": "omni"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
